<template>
  <div id="category-navbar">
    <scroll class="nav-scroll">
      <ul>
        <li
          :class="{ active: currentIndex === index }"
          class="navbar-item"
          v-for="(item, index) in list"
          :key="index"
          @click="navClick(index)"
        >
          {{ item.title }}
        </li>
      </ul>
    </scroll>
  </div>
</template>

<script>
import Scroll from "components/common/scroll/Scroll";

export default {
  name: "CategoryNavbar",
  components: {
    Scroll,
  },
  props: {
    list: {
      type: Array,
      default() {
        return [];
      },
    },
  },
  data() {
    return {
      currentIndex: 0,
    };
  },
  methods: {
    navClick(index) {
      this.currentIndex = index;
      this.$emit("selectItem", index);
    },
  },
};
</script>

<style scoped>
#category-navbar {
  background: #f0f0f0;
  height: 100%;
}
.nav-scroll {
  height: 100%;
  overflow: hidden;
}
.navbar-item {
  height: 6vh;
  line-height: 6vh;
  font-size: 14px;
  text-align: center;
  color: #999999;
}

.active {
  border-left: 5px solid var(--color-tint);
  background: #fff;
  color: var(--color-tint);
  font-size: 16px;
  text-align: left;
  padding-left: 5vw;
}
</style>